<?php
$sAttendance = UserHandler::getAttendance($_SESSION['rid']);
?>
<table class="boxborder" cellspacing="0">
	<tr>
		<td class="boxhandle" colspan="4"><?php print msg('Attendance') ?></td>
	</tr>
	<tr>
		<td class="listtop center">
			<input type="button" onClick="showBox('user-attendanceadd');" value="<?php print msg('Write'); ?>">
		</td>
		<td class="listtop center"><?php print msg('Time') ?></td>
		<td class="listtop center"><?php print msg('In/Out') ?></td>
		<td class="listtop center"><?php print msg('Hours') ?></td>
	</tr>
<?php
for ($i = 0; $i < count($sAttendance); $i++) {
	$iTiming = $sAttendance[$i]['timing'];
	$sType = $sAttendance[$i]['type'];
	$sDate = date('Y-m-d', $iTiming);
	switch ($sType) {
		case 'coming':
			$sTypeString = msg('Here');
			break;
		case 'leaving':
			$sTypeString = msg('Home');
			break;
		case 'brb':
			$sTypeString = msg('Be right back');
			break;
		case 'back':
			$sTypeString = msg('Back to desk');
			break;
		default:
			$sTypeString = msg('Home');
	}
	if ($sDate != @$sPrevDate) {
		?>
		<tr>
			<td class="separator" colspan="4"><?php print $sDate ?></td>
		</tr>
		<?php
	}
	?>
	<tr>
		<td class="listentity nowrap center">
			<input type="button" onClick="showBox('user-attendancedelete', 'iTiming=<?php print $iTiming ?>');" value="<?php print msg('Delete'); ?>">
		</td>
		<td class="listentity center nowrap"><?php print date('H:i:s', $iTiming) ?></td>
		<td class="listentity center"><?php print $sTypeString ?></td>
		<td class="listentity center">
	<?php
	if ($sType == 'leaving' && $sAttendance[$i + 1]['type'] == 'coming') {
		print round(($iTiming - $sAttendance[$i + 1]['timing']) / 60 / 60, 2);
	}
	else {
		print '&nbsp;';
	}
	?>
		</td>
	</tr>
	<?php
	$sPrevDate = $sDate;
}
?>
</table>
